package com.thoughtworks.jspecsupport;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LoadStatementMatcher {

    private final Pattern singleQuotePattern = Pattern.compile("\\s*load\\(\\'[a-zA-Z_0-9\\.\\-]+\\.js\\'\\);?\\s*");
    private final Pattern doubleQuotePattern = Pattern.compile("\\s*load\\(\\\"[a-zA-Z_0-9\\.\\-]+\\.js\\\"\\);?\\s*");

    public boolean isMatch(String line) {
        return singleQuotePattern.matcher(line).matches() || doubleQuotePattern.matcher(line).matches();
    }

    public String match(String line) {
        return line.trim()
                   .replace("load('", "")
                   .replace("');", "")
                   .replace("')", "")
                   .replace("load(\"", "")
                   .replace("\");", "")
                   .replace("\")", "");
    }
}
